package com.lmx.repoDomain.repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lmx.repoDomain.tmodel.NurseGroup;
import com.lmx.persistence.service.NursingService;
import com.lmx.persistence.service.UserService;
import com.lmx.persistence.service.common.DslJpaService;
import com.lmx.repoDomain.tmodel.DicttypeTenant;
import com.lmx.repoDomain.tmodel.Employee;

import io.katharsis.queryParams.QueryParams;
import io.katharsis.repository.annotations.JsonApiAddRelations;
import io.katharsis.repository.annotations.JsonApiRelationshipRepository;
import io.katharsis.repository.annotations.JsonApiRemoveRelations;
import io.katharsis.repository.annotations.JsonApiSetRelation;

@Component
public class NursingGroupToEmployeeRepository extends BaseRelationRepository<NurseGroup, Employee> {

	@Autowired
	protected UserService userService;

	@Autowired
	protected NursingService nursingService;

	public NursingGroupToEmployeeRepository() {
		this.dslJpaService = new DslJpaService<DicttypeTenant>();
		this.dslJpaService.setEntityClass(NurseGroup.class);
	}

	@Override
	@JsonApiSetRelation
	public void setRelation(final NurseGroup group, final Long groupId, final String fieldName) {

	}

	@Override
	@JsonApiAddRelations
	public void addRelations(final NurseGroup group, final Iterable<Long> groupIds, final String fieldName) {
	}

	@Override
	@JsonApiRemoveRelations
	public void removeRelations(final NurseGroup group, final Iterable<Long> groupIds, final String fieldName) {
	}

	@Override
	public void setRelations(final NurseGroup group, final Iterable<Long> groupIds, final String fieldName) {
		// TODO Auto-generated method stub

	}

	@Override
	public Employee findOneTarget(final Long groupId, final String fieldName, final QueryParams queryParams) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Iterable<Employee> findManyTargets(final Long sourceId, final String fieldName,
			final QueryParams queryParams) {
		// NurseGroup group = (NurseGroup)dslJpaService.findById(sourceId);
		NurseGroup group = nursingService.getNurseGroupById(sourceId);
		return userService.getEmployeeByGroup(group);

	}
}
